// eslint-disable-next-line import/namespace
import { Context } from '@nuxt/types'
import apis from './index'
// 所有 api 注册到 this 对象上去
declare module 'vue/types/vue' {
  interface Vue {
    $api: {
      [x: string]: any
    }
  }
}
export default ({ app }: Context, inject: any) => {
  interface IObject {
    [key: string]: Function
  }
  const apiObject: IObject = {}
  for (const i in apis) {
    apiObject[i] = apis[i](app.$axios)
  }

  // 文档: https://www.nuxtjs.cn/guide/plugins
  // https://blog.csdn.net/GoldenLegs/article/details/110930762
  // https://www.cnblogs.com/goloving/p/11440967.html
  // inject:注入到服务端context, vue实例, vuex中
  inject('api', apiObject)
}
